home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / iritsm3s.zip / CAGD_LOC.H < prev    next >
C/C++ Source or Header  |  1992-01-28  |  5KB  |  124 lines

  1. /******************************************************************************
  2. * Cagd_loc.h - header file for the CAGD library.                  *
  3. * This header is local to the library - it is NOT external.              *
  4. *******************************************************************************
  5. * Written by Gershon Elber, Mar. 90.                          *
  6. ******************************************************************************/
  7.  
  8. #ifndef CAGD_LOC_H
  9. #define CAGD_LOC_H
  10.  
  11. #include <stdio.h>
  12. #include <math.h>
  13. #include "irit_sm.h"
  14.  
  15. typedef enum TokenNumType { /* Tokens are returned by _CagdGetToken routines. */
  16.     TOKEN_EOF,
  17.     TOKEN_OPEN_PAREN,
  18.     TOKEN_CLOSE_PAREN,
  19.     TOKEN_BEZIER,
  20.     TOKEN_BSPLINE,
  21.     TOKEN_POWER,
  22.     TOKEN_CURVE,
  23.     TOKEN_SURFACE,
  24.     TOKEN_PTYPE,
  25.     TOKEN_NUM_PTS,
  26.     TOKEN_ORDER,
  27.     TOKEN_KV,
  28.     TOKEN_OTHER
  29. } TokenNumType;
  30.  
  31. /******************************************************************************
  32. * Some lists simplifying operators.                          *
  33. ******************************************************************************/
  34. #define CAGD_LIST_PUSH(New, List)       { (New) -> Pnext = (List); \
  35.                       (List) = (New); }
  36. #define CAGD_LIST_POP(Head, List)    { (Head) = (List); \
  37.                       (List) = (List) -> Pnext; \
  38.                       (Head) -> Pnext = NULL; }
  39. #define CAGD_LIST_LAST(Elem)        { if (Elem) \
  40.                           while ((Elem) -> Pnext) \
  41.                           (Elem) = (Elem) -> Pnext; }
  42.  
  43. /******************************************************************************
  44. * Some points/ectors simplifying operators.                      *
  45. ******************************************************************************/
  46. #define    CAGD_COPY_POINT(DstPt, SrcPt)    { (DstPt) = (SrcPt); }
  47. #define    CAGD_RESET_POINT(DstPt)     { (DstPt).Pt[0] = \
  48.                       (DstPt).Pt[1] = \
  49.                       (DstPt).Pt[2] = 0.0; }
  50. #define    CAGD_ADD_POINT(DstPt, SrcPt)    { (DstPt).Pt[0] += (SrcPt).Pt[0]; \
  51.                       (DstPt).Pt[1] += (SrcPt).Pt[1]; \
  52.                       (DstPt).Pt[2] += (SrcPt).Pt[2]; }
  53. #define    CAGD_SUB_POINT(DstPt, SrcPt)    { (DstPt).Pt[0] -= (SrcPt).Pt[0]; \
  54.                       (DstPt).Pt[1] -= (SrcPt).Pt[1]; \
  55.                       (DstPt).Pt[2] -= (SrcPt).Pt[2]; }
  56. #define    CAGD_MULT_POINT(DstPt, Scaler)  { (DstPt).Pt[0] *= (Scaler); \
  57.                       (DstPt).Pt[1] *= (Scaler); \
  58.                       (DstPt).Pt[2] *= (Scaler); }
  59.  
  60. #define    CAGD_COPY_VECTOR(DstVec, SrcVec) { (DstVec) = (SrcVec); }
  61. #define    CAGD_RESET_VECTOR(DstVec)     { (DstVec).Vec[0] = \
  62.                       (DstVec).Vec[1] = \
  63.                       (DstVec).Vec[2] = 0.0; }
  64. #define    CAGD_ADD_VECTOR(DstVec, SrcVec) { (DstVec).Vec[0] += (SrcVec).Vec[0]; \
  65.                       (DstVec).Vec[1] += (SrcVec).Vec[1]; \
  66.                       (DstVec).Vec[2] += (SrcVec).Vec[2]; }
  67. #define    CAGD_SUB_VECTOR(DstVec, SrcVec) { (DstVec).Vec[0] -= (SrcVec).Vec[0]; \
  68.                       (DstVec).Vec[1] -= (SrcVec).Vec[1]; \
  69.                       (DstVec).Vec[2] -= (SrcVec).Vec[2]; }
  70. #define    CAGD_MULT_VECTOR(DstVec, Scaler){ (DstVec).Vec[0] *= (Scaler); \
  71.                       (DstVec).Vec[1] *= (Scaler); \
  72.                       (DstVec).Vec[2] *= (Scaler); }
  73. #define    CAGD_DIV_VECTOR(DstVec, Scaler) { (DstVec).Vec[0] /= (Scaler); \
  74.                       (DstVec).Vec[1] /= (Scaler); \
  75.                       (DstVec).Vec[2] /= (Scaler); }
  76. #define CAGD_LEN_VECTOR(V)        sqrt(SQR((V).Vec[0]) + \
  77.                          SQR((V).Vec[1]) + \
  78.                          SQR((V).Vec[2]))
  79. #define CAGD_NORMALIZE_VECTOR(V)    { CagdRType __t = CAGD_LEN_VECTOR(V); \
  80.                       if (!APX_EQ(__t, 0.0)) \
  81.                           CAGD_DIV_VECTOR((V), __t); }
  82.  
  83. /******************************************************************************
  84. * This macro is called when the library has detected an unrecoverable error.  *
  85. * Default action is to call CagdFatalError, but you may want to reroute this  *
  86. * to invoke your handler and recover yourself (by long jump for example).     *
  87. ******************************************************************************/
  88. #define FATAL_ERROR(Msg)    CagdFatalError(Msg)
  89.  
  90. #define INFINITY 1e6
  91.  
  92. #define W 0     /* Positions of points in Points array (see structs below). */
  93. #define X 1
  94. #define Y 2
  95. #define Z 3
  96.  
  97. #include "cagd_lib.h"             /* Include the extrenal header as well. */
  98.  
  99. /* Declaration of extrenal variables local to the cagd library only. */
  100. extern int _CagdGlblLineCount;         /* Used to locate errors in input file. */
  101. extern CagdLin2PolyType _CagdLin2Poly;    /* Linear srf convertion to polys. */
  102.  
  103. /* Declarations of functions local to the Cagd library only. */
  104. char *_CagdGetCurveAttributes(FILE *f);
  105. char *_CagdGetSurfaceAttributes(FILE *f);
  106. void _CagdUnGetToken(char *StringToken);
  107. TokenNumType _CagdGetToken(FILE *f, char *StringToken);
  108. char *_CagdReal2Str(double R);
  109. CagdPolygonStruct *_CagdMakePolygon(CagdBType ComputeNormals,
  110.                         CagdPtStruct *Pt1,
  111.                     CagdPtStruct *Pt2,
  112.                     CagdPtStruct *Pt3,
  113.                     CagdVecStruct *Nl1,
  114.                     CagdVecStruct *Nl2,
  115.                         CagdVecStruct *Nl3);
  116.  
  117. #ifdef USE_VARARGS
  118. void _CagdFprintf(FILE *f, int Indent, char *va_alist, ...);
  119. #else
  120. void _CagdFprintf(FILE *f, int Indent, char *Format, ...);
  121. #endif /* USE_VARARGS */
  122.  
  123. #endif /* CAGD_LOC_H */
  124.